﻿@model RegionViewModel
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout.cshtml";    
}
@section _Right {
    @Html.Partial("_Right")
}
<h2>
    Add Region</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.mcdropdown.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.bgiframe.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div class="form-data">
            <table class="table-data">
                <tr>
                    <td class="td-label">
                        <div class="editor-label">
                            @Html.LabelFor(model => model.RegionPID)
                        </div>
                    </td>
                    <td class="td-control">
                        <div class="editor-field">
                            <div class="div-mcdd">
                                <input type="text" name="category" id="category" value="" />
                                @Html.HiddenFor(x => x.RegionPID)
                                @(Html.TreeView(Model.ListRegion)
                                .EmptyContent("No locations have been defined yet!")
                                .Children(m => m.ChildLocations)
                                .HtmlAttributes(new { id = "categorymenu", @class = "mcdropdown_menu" })
                                .ChildrenHtmlAttributes(new { @class = "subItem" })
                                .ItemValue(m => m.ID.ToString())
                                .ItemText(m => m.Name))
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="td-label">
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Name, null, true)
                        </div>
                    </td>
                    <td class="td-control">
                        <div class="editor-field">
                            @Html.EditorFor(model => model.Name)
                            @Html.ValidationMessageFor(model => model.Name)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="td-label">
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Description)
                        </div>
                    </td>
                    <td class="td-control">
                        <div class="editor-field">
                            @Html.EditorFor(model => model.Description)
                            @Html.ValidationMessageFor(model => model.Description)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <p class="dvbutton">
                            <input type="submit" value="Create" />
                        </p>
                    </td>
                </tr>
            </table>
        </div>
    </fieldset>
}
<div class="div-back">
    @Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#category").mcDropdown("#categorymenu", { allowParentSelect: true, select: changeVal });
        var dd = $("#category").mcDropdown();
        // SET VALUE
        dd.setValue(0, true);
    });

    function changeVal() {
        var dd = $("#category").mcDropdown();
        var currentVal = dd.getValue();
        currentVal = currentVal + '';
        currentVal = currentVal.split(",");
        $("#RegionPID").val(currentVal[0]);
    }
</script>